package com.fierce.cloud.ota.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import javax.persistence.Id;
import javax.persistence.Transient;
import javax.validation.constraints.Email;
import java.util.ArrayList;
import java.util.List;


/**
 * @author: Fierce
 * @Date: 2021/2/6 21:51
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {

    /**
     * 用户Id
     */
    @Id
    private Long id;

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 邮箱
     */
    @Email
    private String email;

    /**
     * 角色
     */
    @Transient
    private List<Role> roles;
//
//    public List<SimpleGrantedAuthority> getRoles() {
//        List<SimpleGrantedAuthority> authorities = new ArrayList<>();
//        roles.forEach(role -> authorities.add(new SimpleGrantedAuthority(role.getName())));
//        return authorities;
//    }

}
